package Statistics;
/**
 * Used to keep track of an entities stats
 * @author Hetalar
 * 07/02/2012 
 */
public class Statistics 
{
	private Stat[] stats;
	private int primaryStat;
	private final static int TOTAL_STATS = 21;
	
	public final static int STAT_STR = 0;
	public final static int STAT_DEX = 1;
	public final static int STAT_CON = 2;
	public final static int STAT_WIL = 3;
	public final static int STAT_ARMOR = 4;
	public final static int STAT_CRIT = 5;
	public final static int STAT_RESOURCE_REGEN = 6;
	public final static int STAT_HP_REGEN = 7;
	public final static int STAT_HP_CURRENT = 8;
	public final static int STAT_HP_MAX = 9;
	public final static int STAT_MP_CURRENT = 10;
	public final static int STAT_MP_MAX = 11;
	public final static int STAT_DMG = 12;
	public final static int STAT_SWING_SPEED = 13;
	public final static int STAT_LEVEL = 14;
	public final static int STAT_EXP_CURRENT = 15;
	public final static int STAT_EXP_MAX = 16;
	public final static int STAT_DMG_REDUCTION = 17;
	public final static int STAT_CRIT_RATE = 18;
	public final static int STAT_ATK_POWER = 19;
	public final static int STAT_MVM_SPD = 20;
	
	/**
	 * Constructor
	 */
	public Statistics(int primaryStat)
	{
		stats = new Stat[TOTAL_STATS];
		this.primaryStat = primaryStat;
		initializeStats();
	}
	
	public void setPrimaryStat(int to)
	{
		if(checkWithinRange(to))
		{
			this.primaryStat = to;
		}
	}
	
	public int getPrimaryStat()
	{
		return this.primaryStat;
	}
	
	/**
	 * Initializes all of the stats we are to track. 
	 */
	private void initializeStats()
	{
		//TODO Implement this
	}
	
	/**
	 * Checks to see if the value given (for the stat) is within the stat range.
	 * @param value to check
	 * @return true if it is, false otherwise.
	 */
	private boolean checkWithinRange(int value)
	{
		return value >= 0 && value < TOTAL_STATS;
	}
	
	/**
	 * Gets the value associated with the specified stat.
	 * @param which Stat to look up.
	 * @return The value associated with the Stat, -1 if an invalid 
	 * stat is specified.
	 */
	public double getStatValue(int which)
	{
		double result = -1;
		
		if(checkWithinRange(which))
		{
			result = stats[which].getValue();
		}
		
		return result;
	}
	
	/**
	 * Inceases the specified stat
	 * @param which Stat to increase
	 * @param howMuch to increase it by.
 	 */
	public void increaseStat(int which, double howMuch)
	{
		if(checkWithinRange(which))
		{
			stats[which].increaseValue(howMuch);
		}
	}
	
	
	/**
	 * Decreases the specified stat by the specified amount.
	 * @param which Stat to decrease
	 * @param howMuch to decrease it by.
	 */
	public void decreaseStat(int which, double howMuch)
	{
		if(checkWithinRange(which))
		{
			stats[which].decreaseValue(howMuch);
		}
	}
	
	public void setStat(int which, double newValue)
	{
		if(checkWithinRange(which))
		{
			stats[which].setValue(newValue);
		}
	}
	
	public String saveStats()
	{
		//TODO implement this.
		return "";
	}
	
	public void loadStats()
	{
		//TODO implement this.
	}
}
